package extras.salvation.api.methods;

import org.rsbuddy.tabs.Inventory;

import com.rsbuddy.script.wrappers.Item;

/**
 * @author Salvation
 * @version 1.0
 * @since 20-08-2011
 */
public final class ExtendedInventory {

	/**
	 * @author Salvation
	 * @param ids The ids of this potion where ids[0] is the 1-dosed variant.
	 * @return The doses of this potion.
	 */
	public static int getPotionDoseCount(int[] ids) {
		int count = 0;
		for (int i = 0; i < 4; i++) {
			count += Inventory.getCount(ids) * (i + 1);
		}
		return count;
	}

	/**
	 * @author Salvation
	 * @return The amount of Inventory slots available.
	 */
	public static int getCountFree() {
		return 28 - Inventory.getCount(false);
	}

	/**
	 * @author Salvation
	 * @return <tt>true</tt> If the Inventory has 28 available slot, otherwise <tt>false</tt>.
	 */
	public static boolean isEmpty() {
		return Inventory.getCount(false) == 0;
	}
	
	/**
	 * @author Salvation
	 * @param name The name of the Item to check for.
	 * @return <tt>true</tt> if the Inventory contains this Item.
	 */
	public static boolean contains(final String name) {
		return getItem(name) != null;
	}

	/**
	 * @author Salvation
	 * @param name The name of the Item to get.
	 * @return An instance of Item if the Item was found, otherwise null.
	 */
	public static Item getItem(final String name) {
		for (final Item i : Inventory.getItems()) {
			if (i.getName().toLowerCase().contains(name.toLowerCase())) {
				return i;
			}
		}
		return null;
	}

	/**
	 * @author Salvation
	 * @param item The Item to drop.
	 */
	public static void drop(final Item item) {
			item.interact("Drop");
	}
}